import javax.swing.*;

/**
 * Created by IntelliJ IDEA.
 * User: Роман
 * Date: 17.09.12
 * Time: 21:18
 * To change this template use File | Settings | File Templates.
 */
public class BST<Key extends Comparable<Key>, Value> {
    private Node root;

    private class Node {
        private Value value;
        private Key key;
        Node leftChild, rightChild;

        private Node(Key key, Value value) {
            this.value = value;
            this.key = key;
        }
    }

    public void put(Key key, Value value) {
        root = put(root, key, value);
    }

    private Node put(Node nodeToPut, Key key, Value value) {
        if (nodeToPut == null)
            return new Node(key, value);
        int compare = key.compareTo(nodeToPut.key);
        if (compare < 0) {
            nodeToPut.leftChild = put(nodeToPut.leftChild, key, value);
        } else if (compare > 0) {
            nodeToPut.rightChild = put(nodeToPut.rightChild, key, value);
        } else {
            nodeToPut.value = value;
        }
        return nodeToPut;
    }

    public Value get(Key key) {
        Node x = root;
        while (x != null) {
            int compare = key.compareTo(x.key);
            if (compare < 0) {
                x = x.leftChild;
            } else if (compare > 0) {
                x = x.rightChild;
            } else {
                return x.value;
            }
        }
        return null;
    }

    public void delete(Key key) {

    }

    public Iterable<Key> iterator() {
        return null;
    }
}
